package com.zzy.chapter4.ticket.director;

import cn.hutool.core.util.StrUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class DirectorProxy extends AbstractDirector {

    @Autowired
    private Director director;


    @Override
    public Object buildTicket(String type, String productId, String content, String title, String bankInfo, String taxId) {
        // 1. 参数校验
        String product = this.getProduct(productId);
        if(StrUtil.isNotBlank(bankInfo) && !validateBankInfo(bankInfo)) {
            throw new RuntimeException("银行卡号不合法");
        }
        // 2. 生成票据
        return director.buildTicket(type, product, content, title, bankInfo, taxId);
    }

    private String getProduct(String productId) {
        return "通过productId获取商品";
    }

    private boolean validateBankInfo(String bankInfo) {
        // 校验银行卡号
        System.out.println("校验银行卡号");
        return true;
    }
}
